package com.amkai.mobile.utils.webservice;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.database.Cursor;

import com.amkai.mobile.common.job.MobileJob;
import com.amkai.mobile.common.job.MobileJobResult;
import com.amkai.mobile.common.job.login.MobileLoginJob;
import com.amkai.mobile.common.job.util.ByteSerializer;
import com.amkai.mobile.utils.data.Constants;
import com.amkai.mobile.utils.data.MobileDb;

public class MobileWebService {
	
	private static final String GETVERSION_METHOD_NAME = "getVersion";
	private static final String PROCESSJOB_METHOD_NAME = "processMobileJob";
	private static final String NAMESPACE = "http://aesws.aes.amkai.com/";
	private static final String SOAP_ACTION = NAMESPACE + PROCESSJOB_METHOD_NAME;
	// private static final String NAMESPACE = "urn:aesws";
	//This is the good version
	private static final String URL = "http://10.0.0.104:8080/aesws/aesmws";
	private static final String URLPrefix = "http://";
	
	private static final String URLSuffix  = ":8080/aesws/aesmws";
	String serverString = "";


	public MobileJobResult processMobileJob(MobileJob mobileJob) {
		MobileJobResult result = null;
		 try {
		 SoapObject request = new SoapObject(NAMESPACE,
		 PROCESSJOB_METHOD_NAME);
		 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
		 SoapEnvelope.VER11);
		
//		 MobileLoginJob job = getByUsenameAndPassword("Admin", "Arpad895");
		
		 String bjob = ByteSerializer.serializeObject(mobileJob);
		 request.addProperty("mobileJob", bjob);
					
		 envelope.setOutputSoapObject(request);
		 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
		 androidHttpTransport.call(SOAP_ACTION, envelope);
		 Object so = (Object) envelope.getResponse();
		
		 result = (MobileJobResult) ByteSerializer.deserializeObject(so.toString());
		
		 } catch (Exception E) {
			 E.printStackTrace();		 		 
		 }
		return result;
	}

	public static MobileLoginJob getByUsenameAndPassword(String username, String password) {
		MobileLoginJob result = new MobileLoginJob();
		result.userName = username;
		result.password = password;
		return result;
	}
	
	
	

}
